﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Web;

using System.Data.SqlClient;
using System.Data;

namespace SSCCMembership.Web.Services
{
    [ErrorHandlerBehavior]
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class AbilitiesService
    {

        [OperationContract]
        public string[] GetAbilities()
        {
            // Add your operation implementation here
            string UserName = HttpContext.Current.User.Identity.Name;
            using (var Q = SSCCDatabase.Query("SELECT DISTINCT SSCC_SEC_Abilities.Name FROM SSCC_SEC_Abilities INNER JOIN SSCC_SEC_RoleAbilities ON SSCC_SEC_Abilities.ID = SSCC_SEC_RoleAbilities.AbilityID INNER JOIN SSCC_SEC_Roles ON SSCC_SEC_RoleAbilities.RoleID = SSCC_SEC_Roles.ID INNER JOIN SSCC_SEC_UserRoles ON SSCC_SEC_Roles.ID = SSCC_SEC_UserRoles.RoleID WHERE (SSCC_SEC_UserRoles.UserName = @UserName)", new SqlParameter("@UserName", SqlDbType.VarChar), UserName))
            {
                return Q.Select((R) => R["Name"].ToString()).ToArray();
            }
        }
    }
}
